package cn.service.impl;

import cn.dao.DistrictDao;
import cn.dao.impl.DistrictDaoImpl;
import cn.entity.District;
import cn.service.DistrictService;
import cn.utils.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;

public class DistrictServiceImpl implements DistrictService {

    private DistrictDao districtDao = new DistrictDaoImpl();

    @Override
    public void addNewDistrict(District district) {
        Transaction tx = null;
        try {
            tx = HibernateUtil.getTransaction(HibernateUtil.currentSession());
            districtDao.save(district);
            HibernateUtil.commit(tx);
        } catch (HibernateException e) {
            e.printStackTrace();
            HibernateUtil.rollback(tx);
        }
    }
}
